export default ({ resolve, cwd }) => ({
  outDir: resolve(cwd, './dist'),
  cssTarget: 'chrome61',
  emptyOutDir: true,
  rollupOptions: {
    output: {
      chunkFileNames: 'js/[name]-[hash].js',
      entryFileNames: 'js/[name]-[hash].js',
      assetFileNames({ name: fileName }) {
        const name = fileName as string
        const imageTypes = [
          '.jpg',
          '.jpeg',
          '.png',
          '.gif',
          '.bmp',
          '.svg',
          '.webp',
          '.ico',
        ]
        const fontTypes = ['.ttf', '.otf', '.woff', '.woff2']
        const videoTypes = [
          '.mp4',
          '.mov',
          '.avi',
          '.wmv',
          '.flv',
          '.mkv',
          '.webm',
        ]
        // 图片
        if (imageTypes.some((type) => name.endsWith(type))) {
          return 'images/[name]-[hash].[ext]'
        }
        // 视频
        if (videoTypes.some((type) => name.endsWith(type))) {
          return 'video/[name]-[hash].[ext]'
        }
        // 字体
        if (fontTypes.some((type) => name.endsWith(type))) {
          return 'fonts/[name]-[hash].[ext]'
        }
        // css
        if (name.endsWith('.css')) {
          return 'css/[name]-[hash].css'
        }
        // 其他资源
        return 'assets/[name]-[hash].[ext]'
      },
      manualChunks(id) {
        if (id.includes('node_modules')) {
          const list = id.toString().split('node_modules/')
          const chunkName = list[list.length - 1].split('/')[0].toString()
          return chunkName
        }
      },
    },
    // external: [
    //   'vue',
    //   'vue-demi',
    //   'pinia',
    //   'vue-router',
    //   'axios',
    //   'vant',
    //   'mitt',
    //   'nprogress',
    //   '@vueuse/core',
    //   '@vueuse/shared',
    //   // 'pinia-plugin-persistedstate',
    // ],
  },
})
